/*
 * =====================================================================================
 *
 *       Filename:  test_thread_pool.cxx
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  05/09/2011 09:53:23 AM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Ken Chen (Ken), chen_kenz@emc.com
 *        Company:  EMC
 *
 * =====================================================================================
 */

#ifndef __GXX_EXPERIMENTAL_CXX0X__
#define __GXX_EXPERIMENTAL_CXX0X__
#endif 

#include <iostream>
#include "cl_thread.hxx"
#include "cl_thread_pool.hxx"

using namespace std;
using namespace neo;

class Jobs
{
public:
  void printer(void)
  {
    cout << "printing....\n";
    sleep(1);
  }

  void mailer(void)
  {
    cout << "mailing...\n";
    sleep(1);
  }

  void reader(void)
  {
    cout << "reading...\n";
    sleep(1);
  }

  void writer(void)
  {
    cout << "writing...\n";
    sleep(1);
  }

  void thinker(void)
  {
    cout << "thinking...\n";
    sleep(1);
  }
};

int main(int argc, char* argv[])
{
  Jobs jobs;
  {
  CLThreadPool thrPool(5, CLThreadPool::ROUND_ROBIN);
  thrPool.start();

  thrPool.run(bind(&Jobs::printer, &jobs));
  thrPool.run(bind(&Jobs::mailer, &jobs));
  thrPool.run(bind(&Jobs::reader, &jobs));
  thrPool.run(bind(&Jobs::writer, &jobs));
  thrPool.run(bind(&Jobs::thinker, &jobs));
  thrPool.shutdown();

  cout << "------------\n";
  cout.flush();
  }


  {
  CLThreadPool thrPool2(5, CLThreadPool::RANDOM);
  thrPool2.start();
  thrPool2.run(bind(&Jobs::printer, &jobs));
  thrPool2.run(bind(&Jobs::mailer, &jobs));
  thrPool2.run(bind(&Jobs::reader, &jobs));
  thrPool2.run(bind(&Jobs::writer, &jobs));
  thrPool2.run(bind(&Jobs::thinker, &jobs));
  thrPool2.shutdown();

  cout << "------------\n";
  cout.flush();
  }


  {
  CLThreadPool thrPool3(0, CLThreadPool::ROUND_ROBIN);
  thrPool3.start();
  thrPool3.run(bind(&Jobs::printer, &jobs));
  thrPool3.run(bind(&Jobs::mailer, &jobs));
  thrPool3.run(bind(&Jobs::reader, &jobs));
  thrPool3.run(bind(&Jobs::writer, &jobs));
  thrPool3.run(bind(&Jobs::thinker, &jobs));
  thrPool3.shutdown();

  cout << "------------\n";
  cout.flush();
  }


  {
  CLThreadPool thrPool4;
  thrPool4.start();
  thrPool4.run(bind(&Jobs::printer, &jobs));
  thrPool4.run(bind(&Jobs::mailer, &jobs));
  thrPool4.run(bind(&Jobs::reader, &jobs));
  thrPool4.run(bind(&Jobs::writer, &jobs));
  thrPool4.run(bind(&Jobs::thinker, &jobs));
  thrPool4.shutdown();
  }
}

